<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" v-show="showSearch">
      <el-row :gutter="10">
        <el-col :span="6">
          <el-form-item label="房间" prop="roomId">
            <el-input
              v-model="queryParams.roomId"
              placeholder="请输入房间ID"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="年份" prop="year">
            <el-input
              v-model="queryParams.year"
              placeholder="请输入年份"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="月份" prop="month">
            <el-input
              v-model="queryParams.month"
              placeholder="请输入月份"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="类型" prop="type">
            <el-select
              v-model="queryParams.type"
              placeholder="请选择类型"
              clearable
            >
              <el-option label="物业费" :value="0" />
              <el-option label="车位管理费" :value="1" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="支付状态" prop="payStatus">
            <el-select
              v-model="queryParams.payStatus"
              placeholder="请选择支付状态"
              clearable
            >
              <el-option label="待支付" :value="0" />
              <el-option label="已支付" :value="1" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="billList">
      <el-table-column label="账单ID" align="center" prop="id" />
      <el-table-column label="缴费名称" align="center" prop="name" />
      <el-table-column label="账单金额" align="center" prop="amount" />
      <el-table-column label="年份" align="center" prop="year" />
      <el-table-column label="月份" align="center" prop="month" />
      <el-table-column label="类型" align="center" prop="type">
        <template #default="scope">
          {{ scope.row.type === 0 ? "物业费" : "车位管理费" }}
        </template>
      </el-table-column>
      <el-table-column label="支付状态" align="center" prop="payStatus">
        <template #default="scope">
          {{ scope.row.payStatus === 0 ? "待支付" : "已支付" }}
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="paymentTime" />
      <el-table-column label="房间ID" align="center" prop="roomId" />
      <el-table-column label="车位名称" align="center" prop="parkingNumber" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="PropertyBill">
import { ref, getCurrentInstance } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import { matchCommunity } from "@/common/match";
import { getPropertyBillPage } from "@/api/feeManage";

const { proxy } = getCurrentInstance();
const billList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const addEditDialog = ref(false);
const curRow = ref({});

const queryParams = ref({
  pageNo: 1,
  pageSize: 10,
  roomId: "",
  year: "",
  month: "",
  type: null,
  payStatus: null,
});

/** 查询账单列表 */
function getList() {
  loading.value = true;
  getPropertyBillPage(queryParams.value).then(({ data }) => {
    billList.value = data.records;
    total.value = data.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNo = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 编辑按钮操作 */
function handleEdit(row) {}

getList();
</script>
